/**
获取url地址对应的参数
 **/
function getUrlParam(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
    var result = window.location.search.substr(1).match(reg);
    return result ? decodeURIComponent(result[2]) : null;
}
function GetRequest() {
    var url = decodeURI(decodeURI(location.search));
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1),
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
        return theRequest;
    }
}
/**
 获取图片的参数，进行遍历（轮播图）
 **/
function autoPic(arr) {
    var picHtml = '';
    for (var i in arr) {
        picHtml += '<img class="swiper-slide" src="/' + arr[i] + '">';
    }
    return picHtml;
}

/**
 * 查询友情链接
 */
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/friendlylink/selectAllList',
        success: function (data) {
            var list = data.data, html = '';
            $.each(list, function (i, e) {
                html += '<li><a href="' + e.url + '" target="_blank">' + e.name + '</a></li>'
            });
            $('.footer-list').append(html);
        }
    })
})();
/**
 * 查询底部框的企业信息
 */
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/aboutus/selectAllList',
        success: function (data) {
            $(".name").text(data.data[0].name);  //查询公司名称
            $(".address").text(data.data[0].companyAddress);//查询公司地址
            $(".qq").text(data.data[0].qq);//查询qq
            $(".mailbox").text(data.data[0].email);//查询邮箱
            $(".contactPhone").text(data.data[0].contactPhone);//查询联系电话
        }
    })
})();
/**
 * 查询底部框的产品中心各个系列
 */
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/productcategory/selectAllList',
        success: function (data) {
            var productList = data.data,
                seriesHtml = "";
            $.each(productList, function (i, o) {
                seriesHtml += '<li><a href="../cpzx/cpxl.html?id=' + o.id + '">' + o.name + '</a></li>';
            });
            $(".productFooter-list").html(seriesHtml);
        }
    })
})();

/**
 * 查询底部框的解决方案
 */
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/plancategory/selectAllList',
        success: function (data) {
            var list = data.data,
                solutionHtml = "";
            $.each(list, function (i, o) {
                solutionHtml += '<li><a href="../jjfa.html?categoryID=' + o.id + '">' + o.name + '</a></li>';
            });
            $(".solutionFooter-list").html(solutionHtml);
        }
    })
})();
/*************************pc端的导航栏，查询商品系列、商品详情的标题、解决方案的系列********************************/
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/productcategory/selectAllList',
        success: function (data) {
            var list = data.data, html = "";
            $.each(list, function (i, o) {
                html += '<a class="sidebar-link "  data-target="solution" onclick="selectproduct(' + o.id + ')">' + o.name + '<i class="iconfont icon-jiantou"></i></a>'
            });
            $('.productlist').html(html);
            $(".sidebar-link").eq(0).addClass("active");
            return selectproduct(list[0].id);
        }
    })
})();
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/plancategory/selectAllList',
        success: function (data) {
            var list = data.data, html = "";
            $.each(list, function (i, o) {
                html += '<a class="sidebar-link " data-target="solution" onclick="selectplan(' + o.id + ')">' + o.name + '<i class="iconfont icon-jiantou"></i></a>'
            });
            $('.j-planlist').html(html);
            $(".sidebar-link").eq(0).addClass("active");
            return selectplan(list[0].id);
        }
    })
})();

function selectproduct(id) {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/product/selectAllList',
        data: {categoryID: id},
        success: function (data) {
            var elm = $('.productDetail');
            var list = data.data, html = "";
            elm.empty();
            $.each(list, function (i, o) {
                if(i<9){
                    html += '<li> <a href="https://zlgpy.com/cpzx/cpxl/'+o.id+'.html" class="caption"><div>' + o.name + '</div> <b class="row2">' + o.introduce + '</b></a></li>';
                }

            });
            elm.html(html);
            dotNav();

        }
    })
}

function selectplan(id) {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        data: {categoryID: id},
        url: '/rest/front/plan/selectAllList',
        success: function (data) {
            var elm = $('.j-planDetail');
            var list = data.data, html = "";
            elm.empty();
            $.each(list, function (i, o) {
                if(i<9) {
                    html += '<li><a href="../../../jjfa.html?categoryID=' + id + '" class="caption"><div>' + o.name + '</div> <b class="row2">' + o.introduce + '</b></a></li>';
                }
            });
            elm.html(html);
            dotNav();

        }
    })
}
/*************************移动端端的导航栏，查询商品系列、商品详情的标题、解决方案的系列********************************/
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/product/selectProductList',
        success: function (data) {
            var list = data.data, html = '';
            $.each(list, function (i, e) {
                html += '<div class="secondlist" data-id="' + e.id + '"><div class="series" >' +
                    '<div class="flex nav-item ml10"><div>' + e.name + '</div>' +
                    '<div class="cell-main  clickbetter "><i class="iconfont icon-jiantouxia l pull-right" data-stage="2"></i></div></div><div class="thridlist">';
                $.each(e.productList, function (o, j) {
                    html += '<a href="https://zlgpy.com/cpzx/cpxl/'+j.id+'.html" class="nav-item ml20" data-id="' + j.id + '">' + j.name + '</a>';
                });
                html += '</div></div></div>'
            });
            $('.m-product').append(html);
        }
    })
})();
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/plan/selectPlanList',
        success: function (data) {
            var list = data.data, html = '';
            $.each(list, function (i, e) {
                html += '<div class="secondlist" data-id="' + e.id + '"><div class="series" >\n' +
                    '<div class="flex nav-item ml10"><div>' + e.name + '</div>\n' +
                    '<div class="cell-main  clickbetter "><i class="iconfont icon-jiantouxia l pull-right" data-stage="2"></i></div></div><div class="thridlist">';
                $.each(e.planList, function (o, j) {
                    html += '<a href="../../../jjfa.html?categoryID=' + j.id + '" class="nav-item ml20" data-id="' + j.id + '">' + j.name + '</a>';
                });
                html += '</div></div></div>'
            });
            $('.m-plan').append(html);
        }
    })
})();
(function(){
    $.ajax({
        type: 'GET',
        url: '/rest/front/searchhistory/selectAllList',
        dataType: 'json',
        success: function (data) {
            var list = data.data, html = '';
            $.each(list, function (i, e) {
                html += '<div class="auto-screening-prompt" data-id="' + e.id + '">' + e.name + '</div>'
            });
            $(".hot-search").html(html);
        }
    });
})();
/**
 * *关于各种点击效果
 * */
$(function () {
    $(".solutionHover,.nav-main").mouseenter(function () {
        $(".nav-main").show();
        var elm = $(this).data('type');
        $('.' + elm).show().siblings().hide()
    }).mouseleave(function () {
        $(".nav-main").hide();
    });
    $('.mobile-title').click(function () {
        $('.navlist,.expand').show();
    });
    $(document).on('click', '.clickbetter', function () {
        var btn = $(this).find('i');
        var stage = btn.data('stage');
        stage == '1' ? btn.parents('.firstlist').siblings('.secondlist').slideToggle() : btn.parents('.series ').find('.thridlist').slideToggle();
        btn.hasClass('icon-jiantouxia') ? btn.removeClass('icon-jiantouxia').addClass(
            'icon-jiantoushang') : btn.removeClass(
            'icon-jiantoushang').addClass('icon-jiantouxia');
        btn.parents('.navitem').siblings().find('.secondlist,.thridlist').slideUp();
        btn.parents('.navitem').siblings().find('.clickbetter i').removeClass('icon-jiantoushang').addClass('icon-jiantouxia');
    });
    //pc端导航栏的点击颜色加值
    $(document).on('click','.sidebar-link',function () {
        $(this).addClass('active').siblings().removeClass('active');
    });
    //pc端点击
    $(document).on('click','.static-item',function () {
        var index=$(this).data('index'),el;
        $(this).parent().hasClass('j-questionlist')?el=$('.j-static li'):el=$('.static-new li');
        el.eq(index).show().siblings().hide()
    });
    //点击搜索按钮跳转到搜索页面
    $('#headSearchInp').keyup(function () {
        var val=$(this).val();
        val.length>0?   $("#autoScreening").hide():$("#autoScreening").show();
    });
    $('#headSearchInp').focus(function () {
        $("#autoScreening").show();
    }).blur(function () {
          $("#autoScreening").hide()
    });
    //点击搜索按钮跳转到搜索页面
    $(document).on('mousedown','.auto-screening-prompt,#img-search,.mobile-search',function () {
        var name = $(this).text() || $('#headSearchInp').val()||$('.j-searchinp').val()||'高拍仪';
        window.location.href = "../../../ss.html?name=" + name;
    });
    //pc端的出现联系客服跳转到顶部的效果
    $(window).scroll(function () {
        if ($(window).scrollTop() >= 100) {
            $('.actGotop').fadeIn(300);
        } else {
            $('.actGotop').fadeOut(300);
        }
    });
    $('.gotop').click(function () {
        $('html,body').animate({scrollTop: '0px'}, 400);
    });

//移动端的导航栏的遮罩层
    $('.expand').click(function () {
        $('.navlist,.expand').hide();
    });
//在您的位置点击首页返回到首页、产品中心返回产品中心、产品系列返回产品系列、产品详情返回产品详情、资讯以及资讯详情
    $(".indexBack").click(function(){
        window.location.href="https://zlgpy.com";
    });
    $(".proCenter").click(function(){
        window.location.href="https://zlgpy.com/cpzx.html";
    });



});

//点击pc端点击联系客服，弹出联系客服的确认框，点击取消按钮或者关闭按钮，关闭弹出框
function openModal(){
    $(".modal-scrollable ").show();
}
$("#close,.btn-default").click(function(){
    $(".modal-scrollable ").hide();
});
function dotNav(){
    //多出2行数省略号，pc端的导航栏
    $(".menu-panel-list b,.productTab-menu ul li p").each(function(){
        var maxwidth=35;
        if($(this).text().length >maxwidth){
            $(this).text($(this).text().substring(0,maxwidth));
            $(this).html($(this).html()+'...');
        }
    });
}
//在资讯模块的推荐
function dotNews() {
    $(".li-introduce .p-introduce").each(function () {
        var maxwidth = 47;
        if ($(this).text().length > maxwidth) {
            $(this).text($(this).text().substring(0, maxwidth));
            $(this).html($(this).html() + '...');
        }
    });
}